package com.qiaofang.collectmanage.utils;


import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * @author:ZJ.J
 */
public class RegExUtils {

    private static final Logger logger = LoggerFactory.getLogger(RegExUtils.class);

    public static Pattern p1 = Pattern.compile("(\\d+\\.\\d+)");
    public static Pattern p2 = Pattern.compile("(\\d+)");

    /**
     * 提取小数或者整数
     *
     * @param orginal
     * @return
     */
    public static String getNum(String orginal) {
        String str;
        if (StringUtils.isNotBlank(orginal)) {
            Matcher m = p1.matcher(orginal);
            if (m.find()) {
                str = m.group(1) == null ? "" : m.group(1).trim();
            } else {
                m = p2.matcher(orginal);
                if (m.find()) {
                    str = m.group(1) == null ? "" : m.group(1).trim();
                } else {
                    str = "";
                }
            }
        } else {
            str = "";
        }
        return str;
    }

    public static void main(String[] args) {
        logger.info("{}",getNum("ytfhty53.3分钟前"));
    }
}
